﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Benefit.Models.View
{
    /// <summary>
    /// 交易员日多空数据
    /// </summary>
    public class OperatorDayDirectionInfo
    {
        public List<OperatorDayDirectionInfoData> Datas { get; set; }

        //public OperatorDayDirectionInfo GetOperatorDayDirectionInfo(int tradeHistoryId, int operatorid, bool win, DB.DBManager db)
        //{
        //    OperatorDayDirectionInfo data = new OperatorDayDirectionInfo();
        //    if (win)
        //    {
        //        data.Datas = db.OperatorDayDirectionInfoData.Where(a => a.OperatorId == operatorid).Where(a => a.SumValue > 0).Where(a => a.TradeHistoryId == tradeHistoryId).ToList();
        //    }
        //    else
        //    {
        //        data.Datas = db.OperatorDayDirectionInfoData.Where(a => a.OperatorId == operatorid).Where(a => a.SumValue <= 0).Where(a => a.TradeHistoryId == tradeHistoryId).ToList();
        //    }
        //    return data;
        //}



        //public void InitOperatorDayDirectionInfo(int tradeHistoryId, bool win, DB.DBManager db)
        //{

        //    var operators = db.Operators.ToList();
        //    foreach (Sys.Operator op in operators)
        //    {
        //        OperatorDayDirectionInfo info = new OperatorDayDirectionInfo();
        //        info.Datas = new List<OperatorDayDirectionInfoData>();

        //        List<Sys.Account> accounts = new Sys.DayOperatorAccount().GetDayOperatorAccounts(new Sys.TradeHistory().GetDateTimeFromTradeHistoryId(tradeHistoryId, db), op.Id, db);
        //        foreach (Sys.Account account in accounts)
        //        {
        //            List<Data.Day.AccountDayTradeProduct> infos = new Data.Day.AccountDayTradeProduct().GetAccountDayTradeProduct(account.Id, tradeHistoryId, win, db);
        //            foreach (Data.Day.AccountDayTradeProduct i in infos)
        //            {
        //                List<View.OperatorDayDirectionInfoData> ps = null;
        //                if (i.Direction == 1)
        //                {
        //                    ps = info.Datas.Where(a => a.Direction.Equals("空头")).ToList();
        //                }
        //                else
        //                {
        //                    ps = info.Datas.Where(a => a.Direction.Equals("多头")).ToList();
        //                }
        //                if (ps.Count > 0)
        //                {
        //                    OperatorDayDirectionInfoData data = ps.First();
        //                    data.BillCount = data.BillCount + i.BillCount;
        //                    //   data.SumValue = data.SumValue + Math.Abs(i.Profit);
        //                    data.SumValue = data.SumValue + i.Profit;
        //                }
        //                else
        //                {
        //                    OperatorDayDirectionInfoData data = new OperatorDayDirectionInfoData();
        //                    if (i.Direction == 1)
        //                    {
        //                        data.Direction = "空头";
        //                    }
        //                    else
        //                    {
        //                        data.Direction = "多头";
        //                    }

        //                    data.BillCount = i.BillCount;
        //                    //   data.SumValue = Math.Abs(i.Profit);
        //                    data.SumValue = i.Profit;
        //                    info.Datas.Add(data);
        //                }
        //            }
        //        }
        //        var allSum = info.Datas.Sum(a => a.SumValue);
        //        foreach (OperatorDayDirectionInfoData a in info.Datas)
        //        {
        //            a.Percent = Convert.ToInt32((a.SumValue / allSum) * 100);
        //            a.OperatorId = op.Id;
        //            a.TradeHistoryId = tradeHistoryId;
        //            db.OperatorDayDirectionInfoData.Add(a);
        //        }

        //    }
        //    db.SaveChanges();
        //}

        //public void Delete(int tradeHistoryId, DB.DBManager db)
        //{
        //    var query = db.OperatorDayDirectionInfoData.Where(a => a.TradeHistoryId == tradeHistoryId);
        //    foreach (View.OperatorDayDirectionInfoData d in query)
        //    {
        //        db.OperatorDayDirectionInfoData.Remove(d);
        //    }
        //    db.SaveChanges();
        //}
    }
}
